package main

import (
	"container/list"
	"log"
	"os"
	"strings"
)

func CheckErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func IsEmptyChar(ch byte) bool {
	return ch == '\r' || ch == '\n' || ch == '\t' || ch == ' '
}

func FileExists(name string) bool {
	_, err := os.Stat(name)
	return err == nil
}

func snakeString(s string) string {
	data := make([]byte, 0, len(s)*2)
	j := false
	num := len(s)
	for i := 0; i < num; i++ {
		d := s[i]
		if i > 0 && d >= 'A' && d <= 'Z' && j {
			data = append(data, '_')
		}
		if d != '_' {
			j = true
		}
		data = append(data, d)
	}
	return strings.ToLower(string(data[:]))
}

func ListToArray(li *list.List) []interface{} {
	arr := make([]interface{}, li.Len())
	idex := 0
	for e := li.Front(); e != nil; e = e.Next() {
		arr[idex] = e.Value
		idex++
	}
	return arr
}
